/* J. Andrew Sinclair, Ian O'Grady, Bryn Miller, and Catherine Murphy
   Claremont McKenna College
   
   Email: asinclair@cmc.edu.  
   
   2025 SPPQ "Participation and Competition in Top-Two Elections: Tradeoffs in Election Reform"
   Replication File
   
   File version: 06.18.25, edited 08.01.25 to produce .emf files only for windows users.
   
   This file loads the data and runs the analysis.
   
   
   Note that you will need to set up your own file system by modifying line 67.  
   
   We were originally set up to keep the code in one file folder,
       the data in another file folder,
	      and to put the results into a separate file folder.
		  
   For simplicity for the replication, everything came/went from 
           "SPPQ Replication Final" -- as below.
   
   _____Dropbox
     |______ Primary Projects
	     |______FAQ and Team Paper
		     |_______Team Paper Code 
			 |_______Team Paper Data
			 |_______Team Paper Drafts 
			     |______SPPQ Replication Final
   
*/



/* GETTING SET UP */

* Clear out anything already open:
capture log close
clear all


* Packages and so on.
 ** Set Stata Version (Originally done in 17.0; checked with 18.0)
    version 18.0
 ** Scheme: "burd".  This graphical scheme is no longer available via -findit-.
    capture ssc install scheme-burd, replace
 ** For making tables (used in the appendix): estout.
    capture ssc install estout, replace
 ** For Applying labels (the labmask command).  
    capture ssc install labutil, replace 

* Set working conditions, graphics font, table and figure names:
set more off
graph set window fontface "Times New Roman"
global prefixtab `"Table"'
global prefixfig `"Figure"'
global appprefixfig `"Figure A"'
local tabcount=0
local figcount=0
local appfigcount=0

* ID User Name, File Path Type:		  
if `"`c(os)'"' == "MacOSX" global stem `"/users/`c(username)'/"'
if `"`c(os)'"' == "Windows" global stem `"C:/Users/`c(username)'/"'

* Set Directory.  ##### NOTE! You will need to adjust this to your file path!
global projdir `"${stem}/Dropbox/Primary Projects/FAQ and Team Paper/Team Paper Drafts/SPPQ Replication Final/"'
cd "${projdir}"

* Set up Log File. ##### NOTE! Check the file path!
log using "team_paper_code_log.log", replace

* Open Data.  ##### NOTE! Check the file path!
use "TeamPaper_RegularVersion_2025_0613_replicationset_FINAL.dta"


/* Additional Variables */
  
* Identifying a "safe" district.  You can try other thresholds, if you want! 
generate safeDcutoff = 0
  replace safeDcutoff = 1 if rpvs<40
  replace safeDcutoff = . if CA!=1
  replace safeDcutoff = . if legrace!=1
  label define safeDcutofflabs 0 "RPVS>=40" 1 "RPVS<40"
  label values safeDcutoff safeDcutofflabs 
  label variable safeDcutoff "CA Safe D. Leg. District"
   
* D Primary (pre-period) codes.  You can adjust the bins, if you want!

generate cats_pre_dprimary = .
   replace cats_pre_dprimary = 1 if pre_pctpvote <45 ///
      & wind==1 
   replace cats_pre_dprimary = 2 if pre_pctpvote >= 45 & pre_pctpvote<65 ///
      & wind==1 
   replace cats_pre_dprimary = 3 if pre_pctpvote >=65 & pre_pctpvote<100 ///
      & wind==1 
   replace cats_pre_dprimary = 4 if pre_pctpvote==100 ///
      & wind==1 
   label define cats_pre_dprimarylabs ///
       1 "Under 45%" 2 "45%-65%" 3 "65%-99%" 4 "100% of Vote"
   label values cats_pre_dprimary cats_pre_dprimarylabs
   label variable cats_pre_dprimary "Democratic Primary Type"
   
* Electoral Configuration (Splits the top-two categories by type.)
generate pseudorule = .
   replace pseudorule = 1 if toptwo==0
   replace pseudorule = 2 if toptwo==1 & copartisan==0
   replace pseudorule = 3 if toptwo==1 & copartisan==1
   label define pseudorulelabs 1 "Partisan Primary" 2 "Top-Two Primary to Cross-Party General" 3 "Top-Two Primary to Copartisan General"
   label values pseudorule pseudorulelabs
   label variable pseudorule "Election Configuration"

* Make sure only legislative offices remain when we use the leglevel variable:
   generate leglevel = level
     label values leglevel levelabs
	 recode leglevel (4=.)
  
* Re-label the incumbent variable

generate newincumb = incumb 
   label define newincumblabs 0 "Open Seat" 1 "Incumbent"  
   label values newincumb newincumblabs 
   label variable newincumb "Incumbent Winner"
   
* Create a second level variable with different labels for CA

generate calevel = level 
  label define calevellabs 1 "CA Assembly" 2 "CA Senate" 3 "US House" 4 "CA Statewide"
  label values calevel calevellabs 
   
* Simplify write-in finalist variabel to deal with the tie

generate vs_wi = 0
   replace vs_wi = 1 if ctst_wi_finalist>=1 & toptwo==1
   replace vs_wi = . if gwin!=1
   label define vs_wilabs 0 "Otherwise" 1 "Write-In"
   label values vs_wi vs_wilabs 
   label variable vs_wi "Write-in Opponent"
   
* Create DPVS, Diff

generate dpvs=100-rpvs
  label variable dpvs "Obama 2-Party Presidential Vote Share"
generate topticket_dem_twoparty = 100-topticket_rep_twoparty
  label variable topticket_dem_twoparty "Top Ticket Democratic Vote"
  
  
generate DPVS_diff = .
   replace DPVS_diff = pctgvote-dpvs if wind==1
   label variable DPVS_diff "Democratic Performance"
  

/* Part I: The Trade-Off */

* Table 1: Richard Bloom and AD50 
local tabcount=`tabcount'+1
di "$prefixtab-`tabcount'"

gsort elecyear state level district -pctgvote -pctpvote 




outsheet elecyear dpvs name party pctpvote pctgvote topticket_dem_twoparty ///
         gtotvotes topticket_vote topticket_loss_percent ///
      using "$prefixtab-`tabcount'.txt" ///
      if CA==1 & level==1 & distnum==50 & period==2 , replace 
	  
** Comment in text about AD50 in "the general is the primary"...

list elecyear dpvs name party pctpvote pvoten pctgvote gvoten topticket_dem_twoparty ///
         gtotvotes topticket_vote topticket_loss_percent ///
      if CA==1 & level==1 & distnum==50 & period==2 



* Figure 1: Competitiveness in Leg. General Elections, 2002-2020
local figcount=`figcount'+1
di "$prefixfig-`figcount'"
local tempmsize small

twoway (scatter pctgvote rpvs ///
         if ca==1 & legrace==1 & gwin==1 & party==1 & copartisan==0, ///
		 mcolor(red) msymbol(square_hollow) msize(`tempmsize')) ///
	   (scatter pctgvote rpvs ///
	     if ca==1 & legrace==1 & gwin==1 & party==2 & copartisan==0, ///
		 mcolor(midblue) msymbol(circle_hollow) msize(`tempmsize')) ///
	   (scatter pctgvote rpvs ///
	    if ca==1 & legrace==1 & gwin==1 & party==3 & copartisan==0, ///
		 mcolor(orange) msymbol(triangle_hollow) msize(`tempmsize')) ///		
	   (scatter pctgvote rpvs ///
	     if ca==1 & legrace==1 & gwin==1 & party==1 & copartisan==1, ///
		 mcolor(cranberry) msymbol(square) msize(`tempmsize')) ///
	   (scatter pctgvote rpvs ///
	     if ca==1 & legrace==1 & gwin==1 & party==2 & copartisan==1, ///
	     mcolor(navy) msymbol(circle) msize(`tempmsize')) ///
	   (scatter pctgvote rpvs ///
	     if ca==1 & legrace==1 & gwin==1 & party==3 & copartisan==1, ///
	     mcolor(orange) msymbol(triangle) msize(`tempmsize')) ///
		 if elecyear>=2002, ///
	///
	ytitle("Winner's General Election Vote %") ///
	yline(50, lpattern(dash) lcolor(black)) ///
	ylabel(40(10)100) ///
	xtitle(Republican Presidential Vote Share) ///
	xlabel(0(10)100) ///
	by(, note("") rows(2)) by(, legend(position(6))) ///
	  legend(order(1 "Rep. defeats different party" ///
	               2 "Dem. defeats different party" ///
				   3 "Other defeats different party" ///
				   4 "Rep. defeats Rep." ///
				   5 "Dem. defeats Dem." ///
				   6 "Other defeats Other" ) ///
				   rows(2)) ///
	  scheme(burd) by(elecyear) ysize(4) xsize(9)
  graph display, ysize(4) xsize(9)
  graph export "$prefixfig-`figcount'.pdf", replace
  if `"`c(os)'"' == "Windows" graph export "$prefixfig-`figcount'.emf", replace	  
	
	

* Figure 2: Comparing Competitiveness vs. Rolloff	
local figcount=`figcount'+1
di "$prefixfig-`figcount'"	

twoway (scatter DPVS_diff topticket_loss_percent ///
         if copartisan==0, ///
		 mcolor(midblue) msymbol(circle_hollow) msize(vsmall)) ///
	   (scatter DPVS_diff topticket_loss_percent ///
	     if copartisan==1, ///
		 mcolor(navy) msymbol(circle) msize(small)) ///
	   if ca==1 & legrace==1 & wind==1 & party==2 & rpvs<40 & ncands>=2 & elecyear>=2012, ///
	ytitle("Safe Dem. Candidate Performance:" "Winner Pct. - Obama Pct.") ///
	yline(0, lpattern(dash) lcolor(black)) ///
	ylabel(-50(10)20) ///
	xtitle("Roll Off Pct. vs. Top-Ticket Dem.") ///
	xlabel(0(10)30) ///
	  legend(order(1 "Cross-Party Election Winner" ///
	               2 "Same-Party Election Winner" ) ///
				   rows(1) pos(6)) ///
	  scheme(burd) ysize(4) xsize(6)
  graph export "$prefixfig-`figcount'.pdf", replace	  
  if `"`c(os)'"' == "Windows" graph export "$prefixfig-`figcount'.emf", replace
  


  
  
/* Part II: Meaningful Coalition Size */

* Figure 3
local figcount=`figcount'+1
di "$prefixfig-`figcount'"
twoway (scatter ofreg_pctpvote rpvs if CA==1 & legrace==1 & wind==1 & copartisan==0, ///
                mcolor(midblue) msize(vsmall) msymbol(circle_hollow)) ///
	   (scatter ofreg_pctgvote rpvs if CA==1 & legrace==1 & wind==1 & copartisan==1, ///
	            mcolor(navy) msize(small) msymbol(circle)) ///
		if rpvs<40 & legrace==1 & ctst_dcands>=2, ///
	    ytitle("Safe Dem. District Winner's Vote" "As Percent of District Registered Voters") ///
		       ytitle(, size(small)) ylabel(0(25)75) ///
	    xtitle("District Republican Presidential Vote Share" "From 2008 or 2012") ///
		       xtitle(, size(small)) xlabel(0(10)40) ///
		by(, note("")) ///
		legend(order(1 "Cross-Party Election Primary Vote" ///
		             2 "Same-Party Election General Vote") ///
					 size(small)) ///
		scheme(lean1) xsize(7) ysize(8) ///
		by(calevel distperiod, rows(3)) subtitle(, size(medsmall))
  graph display, xsize(7) ysize(8)
  graph export "$prefixfig-`figcount'.pdf", replace	
  if `"`c(os)'"' == "Windows" graph export "$prefixfig-`figcount'.emf", replace	


 ** In-text comment around Figure 3
	**** (safeD restricts to CA leg races)		     
bys period: tab party safeDcutoff if gwin==1, cell	


bys distperiod copartisan: tab party ctst_dcands if gwin==1 & safeDcutoff==1

 ** In-text comment on Figure 3
bys distperiod copartisan: summ ofreg_pctpvote ofreg_pctgvote ///
               if CA==1 & legrace==1 & wind==1 & rpvs<40 & ctst_dcands>=2

		   
			   
* Figure 4
local figcount=`figcount'+1
di "$prefixfig-`figcount'"			   
graph bar (count) if legrace==1 & CA==1 & rpvs<40, ///
      over(cats_pre_dprimary, label(angle(forty_five))) ///
	  over(leglevel, relabel(1 "CA Assembly" 2 "CA Senate" 3 "U.S. House")) ///
	  bar(1, fcolor(blue) fintensity(inten100) lcolor(black)) ///
	  blabel(bar, color(black)) ///
	  ytitle("Number of Democratic Winners" ///
	         "By Office and Primary Vote Share") ///
	  ylabel(0(30)180) ///
	  by(pseudorule, rows(3) imargin(medium) note("")) ///
	  scheme(burd)	xsize(4.5) ysize(8)		   
  graph display, xsize(4.5) ysize(8) 
  graph export "$prefixfig-`figcount'.pdf", replace	
  if `"`c(os)'"' == "Windows" graph export "$prefixfig-`figcount'.emf", replace	
			   

** In text comment 
bys pseudorule: tab cats_pre_dprimary if CA==1 & legrace==1 & wind==1 & rpvs<40
bys pseudorule: tab cats_pre_dprimary leglevel if CA==1 & legrace==1 & wind==1 & rpvs<40			   
			   
 ** Further, 13 of 24 same-party fractured fields result in reversals:
 tab porder gwin if CA==1 & cats_pre_dprimary==1 & pseudorule==3 & legrace==1 & wind==1 & rpvs<40
			   
			   
			   
  
/*
*** We cut this from the paper, but it's an interesting alternative view on Figure 3:

twoway (scatter ofreg_pctpvote ofreg_pctgvote /// 
          if CA==1 & legrace==1 & wind==1 & rpvs<40 & copartisan==0, /// 
		  mcolor(black) msize(tiny) msymbol(circle_hollow)) /// 
	   (scatter ofreg_pctpvote ofreg_pctgvote /// 
	      if CA==1 & legrace==1 & wind==1 & rpvs<40 & copartisan==1, /// 
		  mcolor(black) msize(small) msymbol(circle)) ///
	   if ctst_dcands>=2, ///
	   yline(50, lpattern(dash) lcolor(black)) ylabel(0(10)100) /// 
	   xline(50, lpattern(dash) lcolor(black)) xlabel(0(10)100) /// 
	   scheme(lean1) by(distperiod)

*/

/* Part III: Write-ins and Behavior */

	
* Figure 5: Tracking the Write-In Cases 
local figcount=`figcount'+1
di "$prefixfig-`figcount'"	  
  
twoway ///
   (connected pctgvote elecyear ///
         if elecyear>=2012 & distnum==46 & level==1, ///
		 lcolor(gray) lpattern(solid) ///
		 mcolor(midblue) msymbol(circle_hollow) msize(vsmall) ///
		 mlabel(pctgvote) mlabformat(%9.1f) mlabcolor(black) mlabpos(12) mlabgap(*2.5) ///
		 sort) ///
   (connected pctgvote elecyear ///
	     if elecyear>=2012 & distnum==33 & level==2, ///
	     lcolor(gray) lpattern(dash) ///
		 mcolor(midblue) msymbol(circle_hollow) msize(vsmall) ///
		 mlabel(pctgvote) mlabformat(%9.1f) mlabcolor(black) mlabpos(6) mlabgap(*2.5) ///
		 sort) ///
  (scatter pctgvote elecyear ///
         if elecyear>=2012 & ///
		   ( ///
		     (distnum==46 & level==1) | ///
		     (distnum==33 & level==2) ///
		   )  ///
		 & copartisan==1, ///
		 mcolor(navy) msymbol(square) msize(medsmall)) ///
  (scatter pctgvote elecyear ///
         if elecyear>=2012 & ///
		   ( ///
		     (distnum==46 & level==1) | ///
		     (distnum==33 & level==2) ///
		   )  ///
		 & ctst_wi_finalist==1, ///
		 mcolor(black) msymbol(circle_hollow) msize(vlarge)) ///		 
    if CA==1 & gwin==1, ///
    title("") ///
	ytitle("Winner's General Election Vote %") ///
	   ylabel(50(10)100) yline(50, lpattern(dash) lcolor(black)) ///
	xtitle("Election Year") ///
	  xlabel(2012(2)2020) xscale(range(2011.5 2020.5)) ///
	legend(order(1 "State Assembly District 46" ///
	             2 "State Senate District 33" ///
				 3 "Copartisan Election" ///
				 4 "Write-In Opponent") ///
		    symxsize(*3) pos(6) rows(2)) ///
	scheme(burd) xsize(6) ysize(3)		   
  graph display, xsize(6) ysize(3) 
  graph export "$prefixfig-`figcount'.pdf", replace
  if `"`c(os)'"' == "Windows" graph export "$prefixfig-`figcount'.emf", replace	
		


** In text

gsort state level district elecyear -pctgvote -pctpvote 

list elecyear level distnum rpvs name pctpvote pctgvote copartisan ctst_wi_finalist ///
 if CA==1 & gwin==1 & period==2 & ((level==1 & distnum==46) | (level==2 & distnum==33))

list elecyear level distnum rpvs name pvote pctpvote pctgvote copartisan ctst_wi_finalist ///
 if CA==1 & period==2 & ((level==1 & distnum==46 & elecyear==2016) | (level==2 & distnum==33 & elecyear==2020))


 /* Appendix */
 
 
 /* A1 */
 
* Competitiveness Regression 

* Figure A-1: Predicting Competitiveness in 2012-2020
local appfigcount=`appfigcount'+1
di "$appprefixfig-`appfigcount'"


reg pctgvote i.copartisan##c.rpvs i.copartisan##i.newincumb i.vs_wi i.level i.elecyear ///
   if CA==1 & legrace==1 & toptwo==1 & wind==1 & ncands>=2
  estimates store m1_main
  
  
estimates restore m1_main 
margins, at(rpvs=(5(5)50) copartisan=(0 1)  ///
            newincumb==0 level==1  vs_wi==0 elecyear==2016)
	
	marginsplot
	
marginsplot, ///
     recast(line) ///
	 recastci(rarea) ///
	 ytitle("Predicted Democratic Winner's General Vote %") /// 
	    ylabel(50(10)100) ///
	 xtitle("Two-Party Republican Vote Share in 2012") ///
	 plot1opts(lcolor(midblue) lpattern(dash)  lwidth(medthick)) ///
	 plot2opts(lcolor(navy)    lpattern(solid) lwidth(medthick)) ///
	 ci1opts(fcolor(eltblue)   fintensity(10)  ///
	         lcolor(black)     lpattern(dot))  ///
	 ci2opts(fcolor(eltblue)      fintensity(25)  ///
	         lcolor(black)     lpattern(dot))  ///		
	 legend(order(3 "Cross-Party Election" 4 "Copartisan Election") ///
	        symxsize(*3) rows(1) pos(6) span)	///
     title("") ///
	 scheme(burd) ysize(4) xsize(6)
  graph display, ysize(4) xsize(6)
  graph export "$appprefixfig-`appfigcount'.pdf", replace
  if `"`c(os)'"' == "Windows" graph export "$appprefixfig-`appfigcount'.emf", replace	  
	
* Table A-1: Regression Results 
estimates restore m1_main 
  estout ///
  using "appendix_m1_main_coefs.txt", ///
  label legend varlabels (_cons Constant) ///
  cells("b(star label(Coef.) fmt(2)) se(label(Std. Err.) fmt(2))") ///
  stats (r2 N, labels(R-squared N)) ///
  replace 

  
  
/* A2 */  
 
* Substituting total primary/general vote instead of winner vote in Figure 3.

  /* This figure uses the *party* primary vote for the total primary vote pre-2012 in CA.  
     For 2012 and after, it just uses the total primary vote because all candidates appear in the same pool.
	 For the general vote, it uses the general election vote totals. */

local appfigcount=`appfigcount'+1
di "$appprefixfig-`appfigcount'"

twoway (scatter ctst_prepvote_ofrv rpvs if CA==1 & legrace==1 & wind==1 & copartisan==0, ///
                mcolor(midblue) msize(vsmall) msymbol(circle_hollow)) ///
	   (scatter ctst_gvote_ofrv rpvs if CA==1 & legrace==1 & wind==1 & copartisan==1, ///
	            mcolor(navy) msize(small) msymbol(circle)) ///
		if rpvs<40 & legrace==1 & ctst_dcands>=2, ///
	    ytitle("Safe Dem. District Winner's Vote" "As Percent of District Registered Voters") ///
		       ytitle(, size(medsmall)) ylabel(0(25)75) ///
	    xtitle("District Republican Presidential Vote Share" "From 2008 or 2012") ///
		       xtitle(, size(medsmall)) xlabel(0(10)40) ///
		by(, note("")) ///
		legend(order(1 "Cross-Party Election Total Primary Vote" ///
		             2 "Same-Party Election Total General Vote")) ///
		scheme(lean1) xsize(7) ysize(8) ///
		by(level distperiod, rows(3)) subtitle(, size(medsmall))
  graph display, xsize(7) ysize(8) 
  graph export "$appprefixfig-`appfigcount'.pdf", replace
  if `"`c(os)'"' == "Windows" graph export "$appprefixfig-`appfigcount'.emf", replace	 
  

 ** To better understand the computations here, consider:
list elecyear name party pvoten pre_ptotvotes ptotvotes gvoten ofreg_pctpvote ofreg_pctgvote ctst_prepvote_ofrv ctst_gvote_ofrv  totalreg if CA==1 & distnum==50 & level==1 & (elecyear==2010 | elecyear==2012)
  *** In 2010: old rules --> 
    *** Add up the AD50 2010 D primary votes (6,314+4,608+2,174+1,695) = 14,791
    *** 14,791/144,764 x 100 = 10.2  (Total Dem Primary Votes / Total RVs) 
  *** In 2012: new rules -->
    *** Add up the AD50 2012 primary votes from ALL candidates (15,947+16,084+15,227+15,155) = 62,413 
	*** 62,413/310,979 x 100 = 20.1
   *** BUT! AD50 wasn't decided in the primary.  So, the last Democrat was defeated in the general election.
    *** Add up the AD50 general votes (93,445+91,740) = 185,185
	*** 185,185/310,979 x 100 = 59.5
  *** Punchline: in 2010, the AD50 "last Democrat" contest involved only 10.2% of the RVs.  
  ***            in 2012, the new AD50 "last Democrat" contest involved 59.5% of the RVs.
  
/* A3 */  
* Write-in version of main competitiveness plot
* Figure X: The Write-in Cases, All Years 2012-2020
local appfigcount=`appfigcount'+1
di "$appprefixfig-`appfigcount'"	

twoway ///
  (scatter pctgvote rpvs if party==1 & copartisan==0 & ctst_wi_finalist_majorparty==1, ///
           mcolor(red) msymbol(square_hollow)) ///
  (scatter pctgvote rpvs if party==2 & copartisan==0 & ctst_wi_finalist_majorparty==1, ///
           mcolor(midblue) msymbol(circle_hollow)) ///
  (scatter pctgvote rpvs if party==1 & copartisan==1 & ctst_wi_finalist_majorparty==1, ///
           mcolor(cranberry) msymbol(square)) ///
  (scatter pctgvote rpvs if party==2 & copartisan==1 & ctst_wi_finalist_majorparty==1, ///
           mcolor(navy) msymbol(circle)) ///
  (scatter pctgvote rpvs if ctst_wi_finalist==2 & elecyear>=2012, ///
           mcolor(gray) msymbol(diamond_hollow) msize(vlarge)) ///
      if CA==1 & legrace==1 & gwin==1, ///
  ytitle("Winner's General Election Vote %") ///
     ylabel(50(10)100) ///
     yline(50, lpattern(dash) lcolor(black)) ///
  xtitle("Republican Presidential Vote Share") ///
     xlabel(0(10)100) ///
  legend(order(1 "Rep. - Different Party" ///
               2 "Dem. - Different Party" ///
	  		   3 "Rep. - Same Party" ///
			   4 "Dem. - Same Party" ///
			   5 "Top-Three Tie") ////
			   rows(3) pos(6)) ///
    scheme(burd) xsize(6) ysize(3) 	   
  graph display, xsize(6) ysize(3) 
  graph export "$appprefixfig-`appfigcount'.pdf", replace
   if `"`c(os)'"' == "Windows" graph export "$appprefixfig-`appfigcount'.emf", replace  
  
  
  
/* A4 Google Search for Appendix */

* Bring in the google trends data
preserve
clear 
import excel "Search_AdrinNazarian.xlsx", firstrow 


labmask oid, values(Year)

* Making Google Search Figure
local appfigcount=`appfigcount'+1
di "$appprefixfig-`appfigcount'"

twoway (line Search_AdrinNazarian oid, ///
             lcolor(black) lwidth(medium) lpattern(solid)) ///
       (scatter Search_AdrinNazarian oid if Election!="", ///
	         mcolor(white) msize(huge) msymbol(circle) ///
			 mlabel(Election) mlabsize(vsmall) mlabcolor(black) ///
			   mlabposition(0) mlcolor(black) mlwidth(thin)), ///
	    ytitle("Relative Google Search" "Los Angeles Metro Area") ylabel(0(10)100) ///
		xtitle("") xlabel(1(12)110, labels angle(forty_five) valuelabel) ///
		legend(off) scheme(burd)
  graph display, xsize(6) ysize(4) 
  graph export "$appprefixfig-`appfigcount'.pdf", replace
  if `"`c(os)'"' == "Windows" graph export "$appprefixfig-`appfigcount'.emf", replace	

* Restore main elections data so it is active when the do file is finished running
restore 

list distnum level if ctst_wi_finalist==2 & elecyear>=2012 & CA==1

* List an example district 

list elecyear level distnum rpvs name party incumb pvoten gvoten totalreg topticket_vote if level==3 & distnum==42 & elecyear==2004

beep
log close
exit


